import $http from '../../fetch/api'

export default {
  state: {
    //存储暂时的值
    dictionary: '', //数据字典解析的值
    methData: [],
    //分割线-------------------------------
    count: 0,
    tableHeightA: (window.innerHeight - 220), //只有一行搜索框的表单高度
    tableHeightB: (window.innerHeight - 258), //有两行搜索框的表单高度
    tableHeightC: ((window.innerHeight - 300) / 2 - 35), //有上下两个表格
    tableHeightD: ((window.innerHeight - 300) / 3 - 25), //仪器计划表单
    tableHeightE: (window.innerHeight - 358 - 38), //仪器记录表格高度
    tableHeightF: window.innerHeight / 2,
    tableHeightH: window.innerHeight / 3,
    tableHeightJ: (window.innerHeight - 500),
    leftmenuStruchFlag: true,
    rightmenuStruchFlag: true,
    nowpage: 'homePage',
    topmenu: '0',
    pageName: '',
    moduleId: '',
    menuName: '',
    //保存按钮状态为草稿 提交按钮状态为启用
    submitType: {'submitDraft': 0, 'submitOpen': 1},
    pageOneName: '',
    opernationData: {},

    //		  	检测结果状态集合
    taskStatusArr: {
      // 540: 'jiancezhong', //'待接收',
      // 541: 'weijiaohe', //'待领取',
      // 542: 'waitExamine', //'待录入',
      // 543: 'chonglu', //'待重录',
      // 544: 'hasExamine', //'待校核',
      // 545: 'hasReview', //'待审核',
      // 546: 'chongcai', //'重采',
      // 547: 'finshed', //'已完成',
      1: {type: 0, label: '无样', value: 1}, //'无样',
      2: {type: 0, label: '草稿', value: 2}, //'干扰',
      3: {type: 0, label: '瓶坏', value: 3}, //'瓶坏',
      4: {type: 0, label: '不测', value: 4}, //'不测',
      5: {type: 0, label: '强制完成', value: 5}, //废弃

      490: {type: 0, label: '草稿', value: 490}, //废弃

      493: {type: 0, label: '废弃', value: 493}, //废弃

      540: {type: 1, label: '待接收', value: 540}, //'待接收',
      541: {type: 1, label: '待领取', value: 541}, //'待领取',
      542: {type: 1, label: '待录入', value: 542}, //'待录入',
      543: {type: 1, label: '待重录', value: 543}, //'重采',
      544: {type: 1, label: '待校核', value: 544}, //'待校核'
      545: {type: 1, label: '待审核', value: 545}, //'待审核',
      546: {type: 1, label: '重采', value: 546}, //'重采',
      547: {type: 1, label: '已完成', value: 547}, //'已完成',

    },


    enableStatus: [{
      value: 0,
      label: '已停用'
    },
      {
        value: 1,
        label: '已启用'
      },
      {
        value: 2,
        label: '草稿'
      },
      {
        value: 3,
        label: '待审核'
      },
      {
        value: 4,
        label: '已驳回'
      },
    ],
    // 检测管理模块状态：5-检测管理模块; 00~09 -检测任务状态码
    taskStatus: [{
      value: 2,
      label: '草稿'
    },
      {
        value: 4,
        label: '已驳回'
      },
      {
        value: 501,
        label: '待签发'
      },
      {
        value: 502,
        label: '待检测'
      },
      // {
      //     value: 503,
      //     label: '检测中'
      // },
      {
        value: 504,
        label: '已完成'
      }
    ],
    // 检测管理模块状态：5-检测管理模块;10~19 -检测样品状态码
    taskSampleStatus: [{
      value: 510,
      label: '待登记'
    },
      {
        value: 511,
        label: '待接收'
      },
      {
        value: 512,
        label: '已作废'
      },
      {
        value: 513,
        label: '待领取'
      },
      {
        value: 514,
        label: '领取中'
      },
      {
        value: 515,
        label: '已完成'
      },
    ],
    reportStatus: [{
      value: '401',
      label: '待审核'
    }, {
      value: '402',
      label: '待签发'
    }, {
      value: '403',
      label: '已完成'
    }, {
      value: '2',
      label: '草稿'
    }, {
      value: '4',
      label: '已驳回'
    },

    ],
    //检测管理模块状态：5-检测管理模块; 20~29 -测试子样品状态码
    testSampleStatus: [{
      value: '520',
      label: '检测中'
    }, {
      value: '521',
      label: '待录入'
    }, {
      value: '522',
      label: '待校核'
    }, {
      value: '523',
      label: '待重录'
    }, {
      value: '524',
      label: '待重测'
    }, {
      value: '525',
      label: '待重采'
    }, {
      value: '526',
      label: '审核中'
    }, {
      value: '527',
      label: '已结束'
    }],
    //检测管理模块状态：5-检测管理模块; 30~39 -检测单状态码
    testBatchStatus: [{
      value: '530',
      label: '待安排'
    }, {
      value: '531',
      label: '待录入'
    }, {
      value: '532',
      label: '待重录'
    }, {
      value: '533',
      label: '待校核'
    }, {
      value: '534',
      label: '待审核'
    }, {
      value: '535',
      label: '已完成'
    },],
    //检测管理模块状态：5-检测管理模块; 40~49 -检测任务中检测项目状态
    taskItemStatus: [{
      value: '540',
      label: '待接收'
    }, {
      value: '541',
      label: '待领取'
    }, {
      value: '542',
      label: '已领取'
    }],
    yesorno: [{
      value: true,
      label: '是'
    },
      {
        value: false,
        label: '否'
      }
    ],
    //是否是主仪器
    isMainEquip: [{
      value: true,
      label: '主仪器'
    },
      {
        value: false,
        label: '辅仪器'
      }
    ],
    // 仪器检查项类型
    mainTenance: [{
      value: 0,
      label: '测试前检查项'
    },
      {
        value: 1,
        label: '测试后检查项'
      }
    ],
    //	1男2女
    sexValue: [{
      code: 1,
      name: '男'
    }, {
      code: 2,
      name: '女'
    }],
    // 质控类型分类
    qcGenre: [{
      label: "现场样",
      value: 'QCA',
      children: [{
        label: "现场-无父样",
        value: 'QCA01',
      }, {
        label: "现场-有父样",
        value: 'QCA02',
      }]
    }, {
      label: "室内样",
      value: 'QCB',
      children: [{
        label: "室内-无父样",
        value: 'QCB01',
      }, {
        label: "室内-有父样",
        value: 'QCB02',
      }, {
        label: "室内-标准样",
        value: 'QCB03',
      }, {
        label: "室内-标准系列样",
        value: 'QCB04', //检测安排引用
      }]
    }],
    groupOption: [
      {
        label: '有父样',
        value: 1,
      }, {
        label: '无父样',
        value: 2,
      }
    ],
    typeOption: [
      {
        label: '空白',
        value: 1,
      }, {
        label: '平行',
        value: 2,
      },
      {
        label: '加标',
        value: 3,
      }, {
        label: '标准样品',
        value: 4,
      }, {
        label: '标准系列样品',
        value: 5,
      },
    ],
    spaceOption: [
      {
        label: '现场样',
        value: 1,
      }, {
        label: '室内样',
        value: 2,
      }
    ],
    typeSelect: [{ //分析项类型
      code: 0,
      name: "普通分析项"
    }, {
      code: 2,
      name: "曲线分析项"
    }, {
      code: 1,
      name: "信号分析项"
    }, {
      code: 3,
      name: "标定分析项"
    }, {
      code: 4,
      name: "标定结果"
    },],

    //目录、权限
    manujson: [],
    //中心目录
    zhongxinmanujson: [{
      "name": "检测管理",
      "page": 'zhongxinTest',
      "sub": [{
        "name": "室间比对任务",
        "page": "homePage",
      },
        {
          "name": "集团考核任务",
          "page": "comparisontask",
        }
      ]
    },
      {
        "name": "统计报表",
        "page": "zhongxinReport",
        "sub": [{
          "name": "水务总览",
          "page": "shuiwuzonglan",
          "sub": []
        },
          {
            "name": "各公司绩效报表",
            "sub": [{
              "name": "水质状况",
              "sub": [{
                "name": "原水",
                'page': 'shuizhirawwater',
                "sub": []
              },
                {
                  "name": "自来水",
                  'page': 'shuizhirunwater',
                  "sub": []
                },
                {
                  "name": "污水",
                  'page': 'shuizhisewagewater',
                  "sub": []
                }
              ]
            },
              {
                "name": "实验室运行状况",
                "sub": [{
                  "name": "原水",
                  'page': 'labrawwater',
                  "sub": []
                },
                  {
                    "name": "自来水",
                    'page': 'labrunwater',
                    "sub": []
                  },
                  {
                    "name": "污水",
                    'page': 'labsewagewater',
                    "sub": []
                  }
                ]
              }
            ]
          },
          {
            "name": "实验室检测数据",
            "page": "shiyanshijiance",
            "sub": []
          },
          {
            "name": "在线监测数据",
            "page": "zaixianjiance",
            "sub": []
          }
        ]
      }
    ],
    //检测单位
    departmentTableDate: [],
    //客户列表
    inspectionUnitTableDate: [],
    //客户列表
    inspectionUnitTableDate2: [],
    //监测区域
    detectionAreaTableDate: [],
    //功能管理、角色管理
    functionTableDate: [],
    //QC类型
    qcGroup: [],
    //业务类别
    businessBigType: [],
    //样品类型
    sampleType: [],
    //监测点类别
    monitorPointBigType: [],
    //能力参数组
    typeofAbilityTableDate: [],
    //能力参数列表
    abilityTableDate: [],
    //方法类别（删）
    methodCategory: [],

    //仪器类型
    eqTypeArr: [],
    //主仪器种类
    mainEquipType: [],
    mainEquipName: [],
    //辅助仪器种类
    frontEquipType: [],
    //分析项类型
    analysisItemType: [],
    //修约规则
    roundingType: [],
    //监测点类型
    monitorPointTypeTableDate: [],
    //供应商
    supplierTableDate: [],
    //分包商列表
    subcontractorTable: [],
    //测试集
    testCollection: [],


    //标准
    standardTableDate: [],
    //标准子集
    standardChildTableDate: [],
    //主仪器列表
    mainEquipTableData: [],
    //前置器列表
    frontEquipTableData: [],
    //物资类型
    materialType: [],
    //指标
    analysisItemTableDate: [],
    //数据字典数据分类
    dataDictionaryType: [],
    //登陆/操作
    logType: [],
    //计量单位
    unitTableDate: [],
    //检测方法
    methodsTableDate: [],
    //角色
    roleTableDate: [],
    //用户
    userTableDate: [],
    //排序方式
    paixufangshi: [],
    //批次列表
    batchTableData: [],
    //循环模式
    cycleMode: [],
    //循环状态
    cycStatus: [{
      value: true,
      label: '开启'
    },
      {
        value: false,
        label: '关闭'
      }
    ],
    //任务类型
    taskTypeTableDate: [],
    waibuorneibu: [],
    //容器类型
    bottleType: [],
    //采样人
    caiyangrenData: [],
    //现场负责人
    xianchangrenData: [],
    //分析项类型
    fenxixiangleixing: [],
    //培训管理
    peixunguanliTable: [],
    //课程类型
    kechengleixing: [],
    detectionPointTableDate: [],

    dataDictionaryLists: '',
    groupSelect: [], //分组
    objectSelect: [], //检测对象
    sampleSelect: [], //样品类型
    monitorSelect: [], //监测点类型
    methodTypeSelect: [], //方法类型
    bottleSelect: [], //容器类型
    maintenanceSelect: [], //维护项类型
    dataSelect: [], //数据类型
    ruleSelect: [], //修约类型
    standardSelect: [], //评价标准分类
    clientSelect: [], //客户类型
    unitSelect: [], //计量单位类型
    supplierSelect: [], //供应商类型
    trainSelect: [], //培训课程类型
    typeQcSelect: [], //qc类型
    areaoptions: [], //检测区域
    EmployeeByLabs: [], //采样人
    bottleOptions: [], //所有的容器
    Subcontractors: [], //外包商
    reportWordList: [], //类型与报告字
    disinfectList: [], //消毒方式
    QCS: [],
    QCS1: [],
    enableMaterTypeList: [],
    supplierList: [], //检定校准单位
    supplierData: [], //获取供应商数据
    daibanItem: null, //待办信息存储
    daibanItemShow: false,
    daiban1: [], //待办流程审核列表
    totalCount: 0, //待办流程审核列表总和
    daiban1load: false, //待办流程审核列表loading
    globalLoading: false,
    unnormalValue: "", //仪器异常值
  },
  mutations: {
    changeGlobalLoad(state, newValue) {
      this.state.globalLoading = newValue
      console.log(this.state.globalLoading, 77878)
    },
    getQcType(state) {
      $http.fetch({
        method: 'post',
        apiUrl: '/qc/readQcTypes.htm',
        params: {genre: "QCA02"},
        isJson: false,
      }).then(res => {
        if (res.code === 0) {
          this.state.QCS = res.data
          this.state.typeQcSelect.itemList = [...this.state.QCS, ...this.state.QCS1]
        } else {
        }
      })
      $http.fetch({
        method: 'post',
        apiUrl: '/qc/readQcTypes.htm',
        params: {genre: "QCA01"},
        isJson: false,
      }).then(res => {
        if (res.code === 0) {
          this.state.QCS1 = res.data
          this.state.typeQcSelect.itemList = [...this.state.QCS, ...this.state.QCS1]
        } else {
        }
      })
    },
    // 数据字典数据
    getDictionary(state) {
      this.state.dataDictionaryLists = JSON.parse(sessionStorage.getItem("dataDictionaryList"))
      for (var i in this.state.dataDictionaryLists) {
        if (this.state.dataDictionaryLists[i].code == 'DA') {
          this.state.groupSelect = this.state.dataDictionaryLists[i] //分组
        } else if (this.state.dataDictionaryLists[i].code == 'DO') {
          this.state.objectSelect = this.state.dataDictionaryLists[i] //检测对象
        } else if (this.state.dataDictionaryLists[i].code == 'DOA') {
          this.state.sampleSelect = this.state.dataDictionaryLists[i] //样品类型
        } else if (this.state.dataDictionaryLists[i].code == 'DOA01') {
          this.state.monitorSelect = this.state.dataDictionaryLists[i] //监测点类型
        } else if (this.state.dataDictionaryLists[i].code == 'ME') {
          this.state.methodTypeSelect = this.state.dataDictionaryLists[i] //方法类型
        } else if (this.state.dataDictionaryLists[i].code == 'CON') {
          this.state.bottleSelect = this.state.dataDictionaryLists[i] //容器类型
        } else if (this.state.dataDictionaryLists[i].code == 'MA') {
          this.state.maintenanceSelect = this.state.dataDictionaryLists[i] //维护项类型
        } else if (this.state.dataDictionaryLists[i].code == 'DT') {
          this.state.dataSelect = this.state.dataDictionaryLists[i] //数据类型
        } else if (this.state.dataDictionaryLists[i].code == 'AC') {
          this.state.ruleSelect = this.state.dataDictionaryLists[i] //修约类型
        } else if (this.state.dataDictionaryLists[i].code == 'ESA') {
          this.state.standardSelect = this.state.dataDictionaryLists[i] //评价标准分类
        } else if (this.state.dataDictionaryLists[i].code == 'CL') {
          this.state.clientSelect = this.state.dataDictionaryLists[i] //客户类型
        } else if (this.state.dataDictionaryLists[i].code == 'UM') {
          this.state.unitSelect = this.state.dataDictionaryLists[i] //计量单位类型
        } else if (this.state.dataDictionaryLists[i].code == 'SU') {
          this.state.supplierSelect = this.state.dataDictionaryLists[i] //供应商类型
        } else if (this.state.dataDictionaryLists[i].code == 'TR') {
          this.state.trainSelect = this.state.dataDictionaryLists[i] //培训课程类型
        } else if (this.state.dataDictionaryLists[i].code == 'QC') {
          this.state.typeQcSelect = this.state.dataDictionaryLists[i] // QC类型

        } else if (this.state.dataDictionaryLists[i].code == 'TA') {
          this.state.reportWordList = this.state.dataDictionaryLists[i] // QC类型
        } else if (this.state.dataDictionaryLists[i].code == 'DF') {
          this.state.disinfectList = this.state.dataDictionaryLists[i] // 消毒方式
        }

      }


    },
    increment(state) {
      this.state.count++
    },
    decrement() {
      this.state.count--
    },

    // 设置待办流程审批数据
    setDaiban1(state, newValue) {
      this.state.daiban1 = newValue
    },
    // 设置待办流程审批总数量
    setTotalCount(state, newValue) {
      this.state.totalCount = newValue
    },
    // 待办流程审批loading
    setDaiban1load(state, newValue) {
      this.state.daiban1load = newValue
    },
    // 左边点击事件
    changenowpage(state, newvalue) {
      this.state.nowpage = newvalue;

    },
    // 头部导航点击事件
    changetopmenu(state, newvalue) {
      this.state.topmenu = newvalue;

    },
    passItem(state, item) {
      this.state.daibanItem = item
    },
    // 控制第一次跳转到界面时是否弹出审核框
    passDaibanItemShow(state, status) {
      state.daibanItemShow = status
    },
    //左边目录弹出与隐藏
    changeleftmenuStruchFlag(state) {
      this.state.leftmenuStruchFlag = !this.state.leftmenuStruchFlag;
    },
    // 代办弹出与隐藏
    changerightmenuStruchFlag(state) {
      this.state.rightmenuStruchFlag = !this.state.rightmenuStruchFlag;
    },
    setAllClients(state, value) {
      state.inspectionUnitTableDate2 = value
    },
    setMonitorZones(state, value) {
      state.areaoptions = value
    },
    opernationInfo(state, value) {
      this.state.opernationData = value

    },
    setEmployeeByLab(state, value) {
      state.EmployeeByLabs = value
    },
    readAllBottles(state, value) {
      state.bottleOptions = value
    },

    setSubcontractor(state, value) {
      state.Subcontractors = value
    },
    setEnableMaterTypeList(state, value) {
      console.log(value)
      if (value.length > 0) {
        if (value[0].children == undefined) {
          state.enableMaterTypeList = [];
        } else {
          state.enableMaterTypeList = value[0].children
        }

      }

    },
    setReadSupplierList(state, value) {
      state.supplierList = value
    },

    setSupplierComboList(state, value) {
      state.supplierData = value
    },

  },
  actions: {

    taskCommonQuery(obj) {
      obj.commit('getQcType');
      obj.dispatch('readEnableMaterTypeList');
      obj.dispatch('readSupplierList')
      obj.dispatch('readSupplierComboList')
    },
    dogetDictionary(obj) {
      obj.commit('getDictionary');
    },
    getAllClients(obj) {
      $http.fetch({
        method: 'post',
        apiUrl: '/client/readAllClients.htm',
        params: null,
        isJson: false,
      }).then(res => {
        if (res.code === 0) {
          obj.commit('setAllClients', res.data);
        }
      })

    },
    getMonitorZones(obj, id) {
      $http.fetch({
        method: 'post',
        apiUrl: '/client/readMonitorZones.htm',
        params: {fRef: id},
        isJson: true,
      }).then(res => {
        if (res.code === 0) {
          obj.commit('setMonitorZones', res.data);
        } else {
        }
      },)

    },
    getOpernation(obj, id) {
      $http.fetch({
        method: 'post',
        apiUrl: '/selUserOpernationByModelId.htm',
        params: {moduleId: id},
        isJson: true,
      }).then(res => {
        if (res.code === 0) {
          obj.commit('opernationInfo', res.data);
        }
      })
    },
    getEmployeeByLab(obj) {
      $http.fetch({
        method: 'post',
        apiUrl: '/resource/readEmployeeByLab.htm',
        params: {name: ''},
        isJson: true,
      }).then(res => {
        if (res.code === 0) {
          obj.commit('setEmployeeByLab', res.data);
        }
      })
    },
    // this.$store.dispatch("getAllBottles");
    getAllBottles(obj) {
      $http.fetch({
        method: 'post',
        apiUrl: '/technology/readAllBottles.htm',
        params: {name: ''},
        isJson: true,
      }).then(res => {
        if (res.code === 0) {
          obj.commit('readAllBottles', res.data);
        }
      })
    },
    getAllSubcontractor(obj) {
      $http.fetch({
        method: 'post',
        apiUrl: '/resource/readAllSubcontractor.htm',
        params: {name: ''},
        isJson: true,
      }).then(res => {
        if (res.code === 0) {
          obj.commit('setSubcontractor', res.data);
        }
      },)
    },

    readEnableMaterTypeList(obj) {
      function isClass(o) {
        if (o === null) return "Null";
        if (o === undefined) return "Undefined";
        return Object.prototype.toString.call(o).slice(8, -1);
      }

      function deepClone(obj) {
        var result, oClass = isClass(obj);
        //确定result的类型
        if (oClass === "Object") {
          result = {};
        } else if (oClass === "Array") {
          result = [];
        } else {
          return obj;
        }
        for (let key in obj) {
          var copy = obj[key];
          if (isClass(copy) === "Object") {
            result[key] = deepClone(copy); //递归调用
          } else if (isClass(copy) === "Array") {
            if (key == 'materialTypeBeanList' && obj[key].length != 0) {
              result['children'] = deepClone(copy)
            }
          } else {
            if (key == 'code') {
              result['value'] = obj[key]
            }
            if (key == 'name') {
              result['label'] = obj[key]
            }
          }
        }
        return result;
      };
      $http.fetch({
        apiUrl: 'technology/readEnableMaterTypeList.htm',
        method: 'post',
        params: null,
      }).then(res => {
        if (res.code === 0) {

          obj.commit('setEnableMaterTypeList', deepClone(res.data));
        }
      })
    },
    readSupplierList(obj) {
      $http.fetch({
        apiUrl: 'resource/readSupplierNames.htm',
        method: 'post',
        params: null,
      }).then(res => {
        if (res.code === 0) {
          obj.commit('setReadSupplierList', res.data);
        }
      })
    },
    readSupplierComboList(obj) {
      $http.fetch({
        apiUrl: 'resource/readSupplierComboList.htm',
        method: 'post',
        params: '',
        isJson: false
      }).then(res => {
        if (res.code == 0) {
          obj.commit('setSupplierComboList', res.data);
        }
      })
    },
    getWorkflowList(obj, page) {
      this.state.totalCount = 0;
      this.state.daiban1 = [];
      let params = {
        type: 2,
        page: page,
        pagecount: 10000
      };
      // this.flowListCount = 0;

      obj.commit('setDaiban1load', true);
      return new Promise((resolve, reject) => {
        $http.fetch({
          method: 'post',
          apiUrl: '/workflow/getWorkflowList.htm',
          params: params,
          isJson: false,
        }).then(res => {
          if (res.code === 0) {
            res.data.forEach((item, index) => {
              item.id = item.businesskey
              //							item.nowpage = this.routerObj["t_supplier"].nowpage[index]
              //							item.topmenu =  this.routerObj["t_supplier"].topmenu[index]
            })
            // this.daiban1 = res.data
            // this.totalCount = res.totalCount
            obj.commit('setDaiban1', res.data);
            obj.commit('setTotalCount', res.totalCount);
            obj.commit('setDaiban1load', false);
            resolve(res)
          }
        },)
      })

    },


  }
}
